package com.genersoft.iot.vmp.gb28181.bean;


import com.google.common.base.Joiner;

import java.util.ArrayList;
import java.util.List;

public class DeviceAlarm {

	private static final String[] priorityArray = {"一级警情", "二级警情", "三级警情", "四级警情"};
	private static final String[] methodArray = {"电话报警", "设备报警", "短信报警", "GPS报警", "视频报警",
													"设备故障报警", "其他报警"};
	private static final String[] type2Array = {"视频丢失报警", "设备防拆报警",
			"存储设备磁盘满报警", "设备高温报警", "设备低温报警"};
	private static final String[] type5Array = {"人工视频报警", "运动目标检测报警", "遗留物检测报警", "物体移除检测报警",
			"绊线检测报警", "入侵检测报警", "逆行检测报警", "徘徊检测报警", "流量统计报警",
			"密度检测报警", "视频异常检测报警", "快速移动报警"};
	private static final String[] type6Array = {"存储设备磁盘故障报警", "存储设备风扇故障报警"};
	private static final String[] eventArray = {"进入区域", "离开区域"};

	/**
	 * 报警序号
	 */
	private String sn;
	/**
	 * 设备Id
	 */
	private String deviceId;

	/**
	 * 通道Id
	 */
	private String channelId;

	/**
	 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情-
	 */
	private String alarmPriority;

	/**
	 * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
	 * 7其他报警;可以为直接组合如12为电话报警或 设备报警-
	 */
	private String alarmMethod;

	/**
	 * 报警时间
	 */
	private String alarmTime;

	/**
	 * 报警内容描述
	 */
	private String alarmDescription;

	/**
	 * 经度
	 */
	private double longitude;

	/**
	 * 纬度
	 */
	private double latitude;

	/**
	 * 报警类型
	 * 报警方式为2时，不携带AlarmType为默认的报警设备报警，
	 * 携带AlarmType取值及对应报警类型如下：1-视频丢失报警；2-设备防拆报警；
	 * 3-存储设备磁盘满报警；4-设备高温报警；5-设备低温报警。报警方式为5时，
	 * 取值如下：1-人工视频报警；2-运动目标检测报警；3-遗留物检测报警；4-物体移除检测报警；
	 * 5-绊线检测报警；6-入侵检测报警；7-逆行检测报警；8-徘徊检测报警；9-流量统计报警；
	 * 10-密度检测报警；11-视频异常检测报警；12-快速移动报警。报警方式为6时，
	 * 取值如下：1-存储设备磁盘故障报警；2-存储设备风扇故障报警
	 */
	private int alarmType;

	/**
	 * 报警类型扩展参数。在入侵检测报警时可携带<EventType>事件类型</EventType>，
	 * 事件类型取值：1-进入区域；2-离开区域
	 */
	private int eventType;

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public String getDeviceId() {
		return deviceId;
	}

	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
	}

	public String getChannelId() {
		return channelId;
	}

	public void setChannelId(String channelId) {
		this.channelId = channelId;
	}

	public String getAlarmPriority() {
		return alarmPriority;
	}

	public void setAlarmPriority(String alarmPriority) {
		this.alarmPriority = alarmPriority;
	}

	public String getAlarmMethod() {
		return alarmMethod;
	}

	public void setAlarmMethod(String alarmMethod) {
		this.alarmMethod = alarmMethod;
	}

	public String getAlarmTime() {
		return alarmTime;
	}

	public void setAlarmTime(String alarmTime) {
		if (alarmTime.contains("T")) {
			alarmTime = alarmTime.replace("T", " ");
		}
		this.alarmTime = alarmTime;
	}

	public String getAlarmDescription() {
		return alarmDescription;
	}

	public void setAlarmDescription(String alarmDescription) {
		this.alarmDescription = alarmDescription;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public int getAlarmType() {
		return alarmType;
	}

	public void setAlarmType(int alarmType) {
		this.alarmType = alarmType;
	}


	public int getEventType() {
		return eventType;
	}

	public void setEventType(int eventType) {
		this.eventType = eventType;
	}

	public String getAlarmPriorityValue() {
		int intValue = -1;
		try {
			intValue = Integer.valueOf(alarmPriority);
		} catch (Exception e) {}
		if (intValue >= 1 && intValue <= priorityArray.length) {
			return priorityArray[intValue - 1];
		}

		return alarmPriority;
	}

	public String getAlarmMethodValue() {
		List<String> values = new ArrayList<>();
		int i = 0;
		while (i < alarmMethod.length()) {
			int intValue = -1;
			try {
				intValue = Integer.valueOf(alarmMethod.substring(i, i + 1));
			} catch (Exception e) {}
			if (intValue >= 1 && intValue <= methodArray.length) {
				values.add(methodArray[intValue - 1]);
			}
			++i;
		}

		return Joiner.on("或").join(values);
	}

	public String getAlarmTypeValue() {
		if (alarmMethod.contains("2")) {
			if (alarmType >= 1 && alarmType <= type2Array.length) {
				return type2Array[alarmType - 1];
			}
		} else if (alarmMethod.contains("5")) {
			if (alarmType >= 1 && alarmType <= type5Array.length) {
				return type5Array[alarmType - 1];
			}
		} else if (alarmMethod.contains("6")) {
			if (alarmType >= 1 && alarmType <= type6Array.length) {
				return type6Array[alarmType - 1];
			}
		}
		return String.valueOf(alarmType);
	}

	public String getEventTypeValue() {
		if (eventType >=1 && eventType <= eventArray.length) {
			return eventArray[eventType - 1];
		}
		return String.valueOf(eventType);
	}
}
